package bk2;

//TriangleFile.java
//the program writes and reads Triangle objects.
import java.io.*;
class Point implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	double x, y;
	public Point(double _x, double _y) {x = _x; y = _y;}
	public String toString() { return "(" + x + ", " + y + ") "; }
}
	
class Triangle implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Point a, b, c;
	Triangle(Point _a, Point _b, Point _c) { a = _a; b = _b; c = _c;}
	public String toString() { return "<" + a.toString()+ b.toString()+ c.toString() + ">";}
}
public class TriangleFile
{
	public static void main(String[] args) 
		throws IOException, ClassNotFoundException  { 	
	Triangle t1 = new Triangle(new Point(-1,0), new Point(1, 0), new Point(0, 1));
	
	ObjectOutputStream out = new 	ObjectOutputStream(new FileOutputStream 	("myObjectFile"));
	out.writeObject(t1);
	out.close();
	
	ObjectInputStream in = new ObjectInputStream (new FileInputStream ("myObjectFile"));
	
	Triangle t2 = (Triangle) in.readObject();
	
	System.out.println(t2.toString());
	in.close();
   }  
} 
